function E = compute_Sobel( P )

X=P;
x=double(X);
[C,L]=size(x);


%必要的变量声明
out = zeros(C,L);

factor =6;
limit = 20;
for I = 2:C-1
    for J = 2:L-1
        result1 = x(I+1,J-1)+2*x(I+1, J)+x(I+1,J+1)...%利用差分模板计算梯度
            -x(I-1, J-1)-2*x(I-1,J)-x(I-1,J+1);
        result2 = x(I-1,J+1)+2*x(I, J+1)+x(I+1,J+1)...
            -x(I-1, J-1)-2*x(I,J-1)-x(I+1,J-1);
        result = max(result1, result2);
        out(I,J) = result/factor;
        if out(I,J) <1
            out(I,J) = 1;
        end
        if out(I,J) >256
            out(I,J) = 256;
        end
    end
end
%二值化
for I = 1:C
    for J = 1:L
        if out(I,J)>=limit
            out(I,J) = 256;
        else
            out(I,J) = 1;
        end
    end
end



E = uint8(out)-1;

end